﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

/// <summary>
/// Баовый класс страниц редактирования объектов
/// </summary>
public class MasterPage_EditControl : System.Web.UI.Page
{
    public void SetAlertForTextBox (string ContolTypeName,string EventName,string FunctionName)
    {
        SetAlertForTextBox(this .Controls ,ContolTypeName,EventName,FunctionName);

    }

    public void SetAlertForTextBox()
    {
        SetAlertForTextBox(this.Controls, "TextBox", "onChange", "ShowAlert()");

    }

    protected string CurrentID
    {
        get
        {

            return Request.QueryString[GlobalConstants.qID];
        }

    }

    protected  string CurrentTagName
    {
        get { return Request.QueryString[GlobalConstants.qTagName]; }
    }


    protected void HideAlert()
    { 
        ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "HideAlert();", true);        
    }
    protected void ShowAlert()
    {
        ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "ShowAlert();", true);
    }

    protected void SetAlertForTextBox(ControlCollection Coll, string ControlName, string EventName, string AttachedFunction)
    {
        foreach (Control item in Coll)
        {
            if (item.Controls.Count > 0) SetAlertForTextBox(item.Controls, ControlName, EventName, AttachedFunction + ";");
            if (item.GetType().FullName.IndexOf(ControlName) > -1)
            {
                WebControl f = (WebControl)item;
                f.Attributes.Add(EventName, AttachedFunction + ";");
            }
        }
    }
}
